package thread;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

public class ThreadDemo16 {

    public static void main(String[] args) {
        BlockingDeque<Integer> blockingDeque = new LinkedBlockingDeque<>();
        Thread t1 = new Thread(()->{
            while(true){
                try {
                    Integer result = blockingDeque.take();
                    System.out.println("消费元素:"+result);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                System.out.println();
            }
        });
        t1.start();

        Thread t2 = new Thread(() ->{
           int i = 1;
           while(i < 1000){
               try {
                   blockingDeque.put(i);
                   System.out.println("生产元素:"+i);
                   i++;
                   Thread.sleep(200);
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
           }
        });
        t2.start();
    }
}
